package com.alibobo.bigsixnineapp;

import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.alibobo.bigsixnineapp.activities.SelectTimeType1Activity;
import com.alibobo.bigsixnineapp.services.imp.SDFileIO;
import com.alibobo.tech5.ganji.GJR;
import com.alibobo.tech5.sixenine.GanJiResourceManager;
import com.alibobo.tech5.sixenine.SixNinePanCreator;
import com.alibobo.tech5.sixenine.pan69.Pan69;
import com.alibobo.utils.calendar.DateUtils;

public class MainActivity extends Activity {

	GanJiResourceManager _gm = new GanJiResourceManager(this);

	Button startClzButton1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		startClzButton1 = (Button) findViewById(R.id.StartClzbutton1);
		initStartClzBtn1();
		GJR.loadRes();

		 SixNinePanCreator creator = new SixNinePanCreator();
		 creator.setResManager(_gm);
		 creator.createFrom("甲寅", 2);

	}

	protected void initStartClzBtn1() {
		startClzButton1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				Bundle b = new Bundle();
				b.putString("test", "hello");
				intent.setClass(MainActivity.this,
						SelectTimeType1Activity.class);
				intent.putExtras(b);
				startActivityForResult(intent, 1);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == -1)
			return;
		String _dateStr = data.getStringExtra("date");
		String _ji = data.getStringExtra("ji");
		Log.i("note", _dateStr + " " + _ji);
		Date dt = DateUtils.parseYYYYMMDD(_dateStr);
		SixNinePanCreator creator = new SixNinePanCreator();
		creator.setResManager(_gm);

		Pan69 pan = creator.createFrom(dt, _ji);

		SDFileIO sdio = new SDFileIO("69");
		sdio.writeObject("pan1", pan);
		Pan69 pan2 = (Pan69) sdio.readObject("pan1");
		int k=pan2.get夜貴().size();

	}
}
